home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / compass1 / compass.jar / CompassCanvas.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-10-24  |  5.3 KB  |  72 lines

  1. import java.util.Calendar;
  2. import java.util.Timer;
  3. import java.util.TimerTask;
  4. import javax.microedition.lcdui.Canvas;
  5. import javax.microedition.lcdui.Font;
  6. import javax.microedition.lcdui.Graphics;
  7.  
  8. class CompassCanvas extends Canvas {
  9.    Compass parent;
  10.    Timer timer;
  11.    // $FF: renamed from: x long[]
  12.    static final long[] field_0 = new long[]{0L, 26L, 52L, 78L, 104L, 130L, 156L, 182L, 207L, 233L, 258L, 284L, 309L, 333L, 358L, 382L, 406L, 430L, 453L, 477L, 499L, 522L, 544L, 566L, 587L, 608L, 629L, 649L, 669L, 688L, 707L, 725L, 743L, 760L, 777L, 793L, 809L, 824L, 838L, 852L, 866L, 878L, 891L, 902L, 913L, 923L, 933L, 942L, 951L, 958L, 965L, 972L, 978L, 983L, 987L, 991L, 994L, 996L, 998L, 999L, 1000L, 999L, 998L, 996L, 994L, 991L, 987L, 983L, 978L, 972L, 965L, 958L, 951L, 942L, 933L, 923L, 913L, 902L, 891L, 878L, 866L, 852L, 838L, 824L, 809L, 793L, 777L, 760L, 743L, 725L, 707L, 688L, 669L, 649L, 629L, 608L, 587L, 566L, 544L, 522L, 499L, 477L, 453L, 430L, 406L, 382L, 358L, 333L, 309L, 284L, 258L, 233L, 207L, 182L, 156L, 130L, 104L, 78L, 52L, 26L};
  13.    // $FF: renamed from: y long[]
  14.    static final long[] field_1 = new long[]{1000L, 999L, 998L, 996L, 994L, 991L, 987L, 983L, 978L, 972L, 965L, 958L, 951L, 942L, 933L, 923L, 913L, 902L, 891L, 878L, 866L, 852L, 838L, 824L, 809L, 793L, 777L, 760L, 743L, 725L, 707L, 688L, 669L, 649L, 629L, 608L, 587L, 566L, 544L, 522L, 500L, 477L, 453L, 430L, 406L, 382L, 358L, 333L, 309L, 284L, 258L, 233L, 207L, 182L, 156L, 130L, 104L, 78L, 52L, 26L, 0L, -26L, -52L, -78L, -104L, -130L, -156L, -182L, -207L, -233L, -258L, -284L, -309L, -333L, -358L, -382L, -406L, -430L, -453L, -477L, -499L, -522L, -544L, -566L, -587L, -608L, -629L, -649L, -669L, -688L, -707L, -725L, -743L, -760L, -777L, -793L, -809L, -824L, -838L, -852L, -866L, -878L, -891L, -902L, -913L, -923L, -933L, -942L, -951L, -958L, -965L, -972L, -978L, -983L, -987L, -991L, -994L, -996L, -998L, -999L};
  15.  
  16.    CompassCanvas(Compass parent) {
  17.       this.parent = parent;
  18.       TimerTask timerTask = new CompassCanvas$1(this);
  19.       this.timer = new Timer();
  20.       this.timer.schedule(timerTask, 60000L, 60000L);
  21.    }
  22.  
  23.    public void paint(Graphics g) {
  24.       g.setColor(16777215);
  25.       g.fillRect(0, 0, ((Canvas)this).getWidth(), ((Canvas)this).getHeight());
  26.       g.setColor(0);
  27.       Calendar now = Calendar.getInstance();
  28.       int h = now.get(10);
  29.       int m = now.get(12);
  30.       int table_index = (h - 1) * 10 + m / 6;
  31.       if (!this.parent.daylightSaving) {
  32.          table_index += 10;
  33.       }
  34.  
  35.       if (table_index > 119) {
  36.          table_index -= 120;
  37.       }
  38.  
  39.       g.setFont(Font.getFont(0, 0, 8));
  40.       int N_height = g.getFont().getHeight();
  41.       int N_margin = 2;
  42.       int line_length = ((Canvas)this).getHeight() / 2 - N_height - 2;
  43.       if (line_length >= 0) {
  44.          int centre_x = ((Canvas)this).getWidth() / 2;
  45.          int centre_y = ((Canvas)this).getHeight() / 2;
  46.          int a = (int)((long)line_length * field_0[table_index] / 1000L);
  47.          int b = (int)((long)line_length * field_1[table_index] / 1000L);
  48.          if (now.get(11) - (this.parent.daylightSaving ? 1 : 0) < 12) {
  49.             a *= -1;
  50.             b *= -1;
  51.          }
  52.  
  53.          if (!this.parent.northern) {
  54.             b *= -1;
  55.          }
  56.  
  57.          int north_x = centre_x + a;
  58.          int north_y = centre_y + b;
  59.          int south_x = centre_x - a;
  60.          int south_y = centre_y - b;
  61.          int east_x = centre_x + b;
  62.          int east_y = centre_y - a;
  63.          int west_x = centre_x - b;
  64.          int west_y = centre_y + a;
  65.          g.drawLine(south_x, south_y, north_x, north_y);
  66.          g.drawLine(east_x, east_y, west_x, west_y);
  67.          int N_char_y = north_y > centre_y ? north_y + 2 : north_y - N_height - 2;
  68.          g.drawChar('N', north_x, N_char_y, 16 | 1);
  69.       }
  70.    }
  71. }
  72.